package com.hmdp.interceptor;

import com.hmdp.dto.UserDTO;
import com.hmdp.utils.UserHolder;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author vvv
 * @date 2023-10-29 23 51
 * discription
 */
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // 1. 从ThreadLocal 里面那User
        UserDTO user = UserHolder.getUser();
        // 2. 如果没有User则拦截
        if (user == null) {
            throw new RuntimeException("请重新登录");
        }
        // 3. 如果有User那么则身份校验成功
        return true;
    }
}
